package emailserving.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

/**
 * Created by jack on 2/1/16.
 */
@Configuration()
@PropertySource("classpath:application.properties")
public class AppMetadataConfig {
    @Autowired
    private Environment env;

    public String getSenderEmail() {
        return getPropertyAsString("emailserver.default_sender_email");
    }

    public String getEmailServerHost() {
        return getPropertyAsString("emailserver.host");
    }

    public int getEmailServerPort() {
        return getPropertyAsInt("emailserver.port");
    }

    public String getEmailServerUserName() {
        return getPropertyAsString("emailserver.username");
    }

    public String getEmailServerPassword() {
        return getPropertyAsString("emailserver.password");
    }

    public boolean getDB_DDL_generate() {
        return getPropertyAsBoolean("db.ddl.generate");
    }

    public boolean getDB_DDL_run() {
        return getPropertyAsBoolean("db.ddl.run");
    }

    public boolean getDB_persist_batching() {
        return getPropertyAsBoolean("db.persistBatching");
    }

    public String getDatabasePlatformName() {
        return getPropertyAsString("database_platform_name");
    }

    public int getDefaultPageSize() {
        return getPropertyAsInt("list.default.pagesize");
    }

    public int getDefaultEmailSendTaskCount(){
        return getPropertyAsInt("default_email_send_task.count");
    }

    public String getJdbcDriverClassName() {
        return getPropertyAsString("jdbc.driverClassName");
    }

    public String getJdbcURL() {
        return getPropertyAsString("jdbc.url");
    }

    public String getJdbcUsername() {
        return getPropertyAsString("jdbc.username");
    }

    public String getJdbcPassword(){
        return getPropertyAsString("jdbc.password");
    }

    public int getJdbcConnectionPoolInitialSize(){
        return getPropertyAsInt("jdbc.connection_pool.initialSize");
    }

    public int getJdbcConnectionPoolMaxTotalSize(){
        return getPropertyAsInt("jdbc.connection_pool.maxTotalSize");
    }

    public boolean getPropertyAsBoolean(String key) {
        return Boolean.valueOf(env.getProperty(key));
    }

    public String getPropertyAsString(String key) {
        return env.getProperty(key);
    }

    public int getPropertyAsInt(String key) {
        return Integer.valueOf(env.getProperty(key));
    }



}
